﻿using MXComponent.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MXComponent.DAL
{
    public partial class materialwarehouseDB
    {
        #region 成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <returns>是否存在</returns>
        public bool Exists()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from materialwarehouse");
            strSql.Append(" where ");
            SqlParameter[] parameters = {
                };

            return Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters)) != 0;
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(materialwarehouseData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into materialwarehouse(");
            strSql.Append(@"warehouseno,materialid,highspeed,mediumspeed,lowspeed,beforeclose,contacttime,active,createtime,creatby,warehousename,highspeedplc,mediumspeedplc,lowspeedplc,beforecloseplc,contacttimeplc,statusplc,finishcountplc,planqtyplc,errorqtyplc,realqtyplc,saveflagplc,djhighspeed,djhighspeedplc,djlowspeed,djlowspeedplc,djmediumspeed,djmediumspeedplc)");
            strSql.Append(" values (");
            strSql.Append(@"@warehouseno,@materialid,@highspeed,@mediumspeed,@lowspeed,@beforeclose,@contacttime,@active,@createtime,@creatby,@warehousename,@highspeedplc,@mediumspeedplc,@lowspeedplc,@beforecloseplc,@contacttimeplc,@statusplc,@finishcountplc,@planqtyplc,@errorqtyplc,@realqtyplc,@saveflagplc,@djhighspeed,@djhighspeedplc,@djlowspeed,@djlowspeedplc,@djmediumspeed,@djmediumspeedplc)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@warehouseno", SqlDbType.Int),
                    new SqlParameter("@materialid", SqlDbType.Int),
                    new SqlParameter("@highspeed", SqlDbType.Int),
                    new SqlParameter("@mediumspeed", SqlDbType.Int),
                    new SqlParameter("@lowspeed", SqlDbType.Int),
                    new SqlParameter("@beforeclose", SqlDbType.Int),
                    new SqlParameter("@contacttime", SqlDbType.Int),
                    new SqlParameter("@active", SqlDbType.Int),
                    new SqlParameter("@createtime", SqlDbType.DateTime),
                    new SqlParameter("@creatby", SqlDbType.Int),
                    new SqlParameter("@warehousename", SqlDbType.NVarChar,50),
                    new SqlParameter("@highspeedplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@mediumspeedplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@lowspeedplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@beforecloseplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@contacttimeplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@statusplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@finishcountplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@planqtyplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@errorqtyplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@realqtyplc", SqlDbType.NVarChar,10),
                    new SqlParameter("@saveflagplc", SqlDbType.NVarChar,10),
                     new SqlParameter("@djhighspeed", SqlDbType.Int),
                     new SqlParameter("@djhighspeedplc", SqlDbType.NVarChar,10),
                      new SqlParameter("@djlowspeed", SqlDbType.Int),
                       new SqlParameter("@djlowspeedplc", SqlDbType.NVarChar,10),
                          new SqlParameter("@djmediumspeed", SqlDbType.Int),
                       new SqlParameter("@djmediumspeedplc", SqlDbType.NVarChar,10)
            };
            parameters[0].Value = model.warehouseno;
            parameters[1].Value = model.materialid;
            if (model.highspeed == null)
            {
                parameters[2].Value = DBNull.Value;
            }
            else
            {
                parameters[2].Value = model.highspeed;
            }
            if (model.mediumspeed == null)
            {
                parameters[3].Value = DBNull.Value;
            }
            else
            {
                parameters[3].Value = model.mediumspeed;
            }
            if (model.lowspeed == null)
            {
                parameters[4].Value = DBNull.Value;
            }
            else
            {
                parameters[4].Value = model.lowspeed;
            }
            if (model.beforeclose == null)
            {
                parameters[5].Value = DBNull.Value;
            }
            else
            {
                parameters[5].Value = model.beforeclose;
            }
            if (model.contacttime == null)
            {
                parameters[6].Value = DBNull.Value;
            }
            else
            {
                parameters[6].Value = model.contacttime;
            }
            
            parameters[7].Value = model.active;
            parameters[8].Value = model.createtime == string.Empty ? null : model.createtime;
            parameters[9].Value = model.creatby;
            parameters[10].Value = model.warehousename;
            parameters[11].Value = model.highspeedplc ?? DBNull.Value.ToString();
            parameters[12].Value = model.mediumspeedplc ?? DBNull.Value.ToString();
            parameters[13].Value = model.lowspeedplc ?? DBNull.Value.ToString();
            parameters[14].Value = model.beforecloseplc ?? DBNull.Value.ToString();
            parameters[15].Value = model.contacttimeplc ?? DBNull.Value.ToString();
            parameters[16].Value = model.statusplc ?? DBNull.Value.ToString();
            parameters[17].Value = model.finishcountplc ?? DBNull.Value.ToString();
            parameters[18].Value = model.planqtyplc ?? DBNull.Value.ToString();
            parameters[19].Value = model.errorqtyplc ?? DBNull.Value.ToString();
            parameters[20].Value = model.realqtyplc ?? DBNull.Value.ToString();
            parameters[21].Value = model.saveflagplc ?? DBNull.Value.ToString();
            if (model.djhighspeed == null)
            {
                parameters[22].Value = DBNull.Value;
            }
            else
            {
                parameters[22].Value = model.djhighspeed;
            }
            
            parameters[23].Value = model.djhighspeedplc ?? DBNull.Value.ToString();
            if (model.djlowspeed == null)
            {
                parameters[24].Value = DBNull.Value;
            }
            else
            {
                parameters[24].Value = model.djlowspeed;
            }
            
            parameters[25].Value = model.djlowspeedplc ?? DBNull.Value.ToString();
            if (model.djmediumspeed == null)
            {
                parameters[26].Value = DBNull.Value;
            }
            else
            {
                parameters[26].Value = model.djmediumspeed;
            }
            
            parameters[27].Value = model.djmediumspeedplc ?? DBNull.Value.ToString();
            int id = 0;
            object ret = SqlHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters);

            if (ret != null && ret != DBNull.Value)
            {
                id = int.Parse(ret.ToString());
            }
            return id;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public void ModifyRecord(materialwarehouseData model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            strSql.Append("update materialwarehouse set ");

            Dictionary<string, SqlParameter> dic = new Dictionary<string, SqlParameter>();
            dic.Add("warehouseid", new SqlParameter("@warehouseid", SqlDbType.Int));


            if (model.warehouseno != -1)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", warehouseno=@warehouseno");
                }
                else
                {
                    strSql1.Append("warehouseno=@warehouseno");
                }
                dic.Add("warehouseno", new SqlParameter("@warehouseno", SqlDbType.Int));
            }
            if (model.materialid != -1)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", materialid=@materialid");
                }
                else
                {
                    strSql1.Append("materialid=@materialid");
                }
                dic.Add("materialid", new SqlParameter("@materialid", SqlDbType.Int));
            }
            if (model.highspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", highspeed=@highspeed");
                }
                else
                {
                    strSql1.Append("highspeed=@highspeed");
                }
                dic.Add("highspeed", new SqlParameter("@highspeed", SqlDbType.Int));
            }
            if (model.djhighspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djhighspeed=@djhighspeed");
                }
                else
                {
                    strSql1.Append("djhighspeed=@djhighspeed");
                }
                dic.Add("djhighspeed", new SqlParameter("@djhighspeed", SqlDbType.Int));
            }
            if (model.mediumspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", mediumspeed=@mediumspeed");
                }
                else
                {
                    strSql1.Append("mediumspeed=@mediumspeed");
                }
                dic.Add("mediumspeed", new SqlParameter("@mediumspeed", SqlDbType.Int));
            }
            if (model.lowspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", lowspeed=@lowspeed");
                }
                else
                {
                    strSql1.Append("lowspeed=@lowspeed");
                }
                dic.Add("lowspeed", new SqlParameter("@lowspeed", SqlDbType.Int));
            }
            if (model.djlowspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djlowspeed=@djlowspeed");
                }
                else
                {
                    strSql1.Append("djlowspeed=@djlowspeed");
                }
                dic.Add("djlowspeed", new SqlParameter("@djlowspeed", SqlDbType.Int));
            }
            if (model.djmediumspeed != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djmediumspeed=@djmediumspeed");
                }
                else
                {
                    strSql1.Append("djmediumspeed=@djmediumspeed");
                }
                dic.Add("djmediumspeed", new SqlParameter("@djmediumspeed", SqlDbType.Int));
            }
            if (model.beforeclose != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", beforeclose=@beforeclose");
                }
                else
                {
                    strSql1.Append("beforeclose=@beforeclose");
                }
                dic.Add("beforeclose", new SqlParameter("@beforeclose", SqlDbType.Int));
            }
            if (model.contacttime != null)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", contacttime=@contacttime");
                }
                else
                {
                    strSql1.Append("contacttime=@contacttime");
                }
                dic.Add("contacttime", new SqlParameter("@contacttime", SqlDbType.Int));
            }
            if (model.active != -1)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", active=@active");
                }
                else
                {
                    strSql1.Append("active=@active");
                }
                dic.Add("active", new SqlParameter("@active", SqlDbType.Int));
            }

            if (model.updatetime != null && model.updatetime != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", updatetime=@updatetime");
                }
                else
                {
                    strSql1.Append("updatetime=@updatetime");
                }
                dic.Add("updatetime", new SqlParameter("@updatetime", SqlDbType.DateTime));
            }
            if (model.updateby != -1)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", updateby=@updateby");
                }
                else
                {
                    strSql1.Append("updateby=@updateby");
                }
                dic.Add("updateby", new SqlParameter("@updateby", SqlDbType.Int));
            }

            if (model.warehousename != null && model.warehousename != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", warehousename=@warehousename");
                }
                else
                {
                    strSql1.Append("warehousename=@warehousename");
                }
                dic.Add("warehousename", new SqlParameter("@warehousename", SqlDbType.NVarChar));
            }

            if (model.highspeedplc != null && model.highspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", highspeedplc=@highspeedplc");
                }
                else
                {
                    strSql1.Append("highspeedplc=@highspeedplc");
                }
                dic.Add("highspeedplc", new SqlParameter("@highspeedplc", SqlDbType.NVarChar));
            }
            if (model.djhighspeedplc != null && model.djhighspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djhighspeedplc=@djhighspeedplc");
                }
                else
                {
                    strSql1.Append("djhighspeedplc=@djhighspeedplc");
                }
                dic.Add("djhighspeedplc", new SqlParameter("@djhighspeedplc", SqlDbType.NVarChar));
            }
            if (model.mediumspeedplc != null && model.mediumspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", mediumspeedplc=@mediumspeedplc");
                }
                else
                {
                    strSql1.Append("mediumspeedplc=@mediumspeedplc");
                }
                dic.Add("mediumspeedplc", new SqlParameter("@mediumspeedplc", SqlDbType.NVarChar));
            }
            if (model.lowspeedplc != null && model.lowspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", lowspeedplc=@lowspeedplc");
                }
                else
                {
                    strSql1.Append("lowspeedplc=@lowspeedplc");
                }
                dic.Add("lowspeedplc", new SqlParameter("@lowspeedplc", SqlDbType.NVarChar));
            }
            if (model.djlowspeedplc != null && model.lowspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djlowspeedplc=@djlowspeedplc");
                }
                else
                {
                    strSql1.Append("djlowspeedplc=@djlowspeedplc");
                }
                dic.Add("djlowspeedplc", new SqlParameter("@djlowspeedplc", SqlDbType.NVarChar));
            }
            if (model.djmediumspeedplc != null && model.djmediumspeedplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", djmediumspeedplc=@djmediumspeedplc");
                }
                else
                {
                    strSql1.Append("djmediumspeedplc=@djmediumspeedplc");
                }
                dic.Add("djmediumspeedplc", new SqlParameter("@djmediumspeedplc", SqlDbType.NVarChar));
            }
            if (model.beforecloseplc != null && model.beforecloseplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", beforecloseplc=@beforecloseplc");
                }
                else
                {
                    strSql1.Append("beforecloseplc=@beforecloseplc");
                }
                dic.Add("beforecloseplc", new SqlParameter("@beforecloseplc", SqlDbType.NVarChar));
            }
            if (model.contacttimeplc != null && model.contacttimeplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", contacttimeplc=@contacttimeplc");
                }
                else
                {
                    strSql1.Append("contacttimeplc=@contacttimeplc");
                }
                dic.Add("contacttimeplc", new SqlParameter("@contacttimeplc", SqlDbType.NVarChar));
            }
            if (model.statusplc != null && model.statusplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", statusplc=@statusplc");
                }
                else
                {
                    strSql1.Append("statusplc=@statusplc");
                }
                dic.Add("statusplc", new SqlParameter("@statusplc", SqlDbType.NVarChar));
            }
            if (model.finishcountplc != null && model.finishcountplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", finishcountplc=@finishcountplc");
                }
                else
                {
                    strSql1.Append("finishcountplc=@finishcountplc");
                }
                dic.Add("finishcountplc", new SqlParameter("@finishcountplc", SqlDbType.NVarChar));
            }
            if (model.realqtyplc != null && model.realqtyplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", realqtyplc=@realqtyplc");
                }
                else
                {
                    strSql1.Append("realqtyplc=@realqtyplc");
                }
                dic.Add("realqtyplc", new SqlParameter("@realqtyplc", SqlDbType.NVarChar));
            }
            if (model.planqtyplc != null && model.planqtyplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", planqtyplc=@planqtyplc");
                }
                else
                {
                    strSql1.Append("planqtyplc=@planqtyplc");
                }
                dic.Add("planqtyplc", new SqlParameter("@planqtyplc", SqlDbType.NVarChar));
            }
            if (model.errorqtyplc != null && model.errorqtyplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", errorqtyplc=@errorqtyplc");
                }
                else
                {
                    strSql1.Append("errorqtyplc=@errorqtyplc");
                }
                dic.Add("errorqtyplc", new SqlParameter("@errorqtyplc", SqlDbType.NVarChar));
            }
            if (model.saveflagplc != null && model.saveflagplc != string.Empty)
            {
                if (strSql1 != null && strSql1.ToString() != string.Empty)
                {
                    strSql1.Append(", saveflagplc=@saveflagplc");
                }
                else
                {
                    strSql1.Append("saveflagplc=@saveflagplc");
                }
                dic.Add("saveflagplc", new SqlParameter("@saveflagplc", SqlDbType.NVarChar));
            }
            strSql.Append(strSql1);
            strSql.Append(" where warehouseid=@warehouseid");

            SqlParameter[] parameters = null;

            if (dic.Count > 0)
            {
                parameters = new SqlParameter[dic.Count];

                int i = 0;
                BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
                foreach (KeyValuePair<string, SqlParameter> obj in dic)
                {
                    parameters[i] = obj.Value;
                    PropertyInfo propinfo = model.GetType().GetProperty(obj.Key, flag);
                    //if (propinfo.PropertyType.FullName.ToUpper().CompareTo("SYSTEM.GUID") == 0)
                    //{
                    //    if ((Guid)propinfo.GetValue(model, null) == Guid.Empty)
                    //    {
                    //        parameters[i].Value = DBNull.Value;
                    //    }
                    //    else
                    //    {
                    //        parameters[i].Value = propinfo.GetValue(model, null);
                    //    }
                    //}
                    //else
                    //{
                    //    parameters[i].Value = propinfo.GetValue(model, null);
                    //}
                    parameters[i].Value = propinfo.GetValue(model, null);
                    i++;
                }
            }

            SqlHelper.ExecteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void DeleteRecord()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete materialwarehouse");
            strSql.Append(" where ");
            SqlParameter[] parameters = {
                };

            SqlHelper.ExecteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="materialid">主键值</param>
        public void DeleteRecord(int warehouseid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update materialwarehouse set active=0 ");
            strSql.Append(" where warehouseid = @warehouseid ");
            SqlParameter[] parameters = {
                    new SqlParameter("@warehouseid", SqlDbType.Int)
                };
            parameters[0].Value = warehouseid;

            SqlHelper.ExecteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }
        /// <summary>
        /// 得到一个model
        /// </summary>
        /// <returns>model</returns>
        public materialwarehouseData GetModel(int warehouseid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select warehouseid,warehouseno,warehousename,materialid,highspeed,mediumspeed,lowspeed,beforeclose,contacttime,active,createtime,creatby,
                            updatetime,updateby,highspeedplc,mediumspeedplc,lowspeedplc,beforecloseplc,contacttimeplc,statusplc,finishcountplc,planqtyplc,errorqtyplc,realqtyplc,saveflagplc,djhighspeed,djhighspeedplc,djlowspeed,djlowspeedplc,djmediumspeed,djmediumspeedplc from materialwarehouse");
            strSql.Append(" where warehouseid=@warehouseid");
            SqlParameter[] parameters = {
             new SqlParameter("@warehouseid", SqlDbType.Int)
                };

            parameters[0].Value = warehouseid;
            materialwarehouseData model = new materialwarehouseData();
            DataSet ds = SqlHelper.ExecuteDataSet(CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["warehouseid"] != DBNull.Value)
                {
                    model.warehouseid = Convert.ToInt32(row["warehouseid"].ToString());
                }
                if (row["warehouseno"] != DBNull.Value)
                {
                    model.warehouseno = Convert.ToInt32(row["warehouseno"].ToString());
                }
                if (row["warehousename"] != DBNull.Value)
                {
                    model.warehousename = Convert.ToString(row["warehousename"].ToString());
                }
                if (row["materialid"] != DBNull.Value)
                {
                    model.materialid = Convert.ToInt32(row["materialid"].ToString());
                }
                if (row["highspeed"] != DBNull.Value)
                {
                    model.highspeed = Convert.ToInt32(row["highspeed"].ToString());
                }
                if (row["djhighspeed"] != DBNull.Value)
                {
                    model.djhighspeed = Convert.ToInt32(row["djhighspeed"].ToString());
                }
                if (row["mediumspeed"] != DBNull.Value)
                {
                    model.mediumspeed = Convert.ToInt32(row["mediumspeed"].ToString());
                }
                if (row["lowspeed"] != DBNull.Value)
                {
                    model.lowspeed = Convert.ToInt32(row["lowspeed"].ToString());
                }
                if (row["djlowspeed"] != DBNull.Value)
                {
                    model.djlowspeed = Convert.ToInt32(row["djlowspeed"].ToString());
                }
                if (row["djmediumspeed"] != DBNull.Value)
                {
                    model.djmediumspeed = Convert.ToInt32(row["djmediumspeed"].ToString());
                }
                if (row["beforeclose"] != DBNull.Value)
                {
                    model.beforeclose = Convert.ToInt32(row["beforeclose"].ToString());
                }
                if (row["contacttime"] != DBNull.Value)
                {
                    model.contacttime = Convert.ToInt32(row["contacttime"].ToString());
                }
                if (row["active"] != DBNull.Value)
                {
                    model.active = Convert.ToInt32(row["active"].ToString());
                }
                if (row["createtime"] != DBNull.Value)
                {
                    model.createtime = Convert.ToString(row["createtime"].ToString());
                }
                if (row["creatby"] != DBNull.Value)
                {
                    model.creatby = Convert.ToInt32(row["creatby"].ToString());
                }
                if (row["updatetime"] != DBNull.Value)
                {
                    model.updatetime = Convert.ToString(row["updatetime"].ToString());
                }
                if (row["updateby"] != DBNull.Value)
                {
                    model.updateby = Convert.ToInt32(row["updateby"].ToString());
                }
                if (row["highspeedplc"] != DBNull.Value)
                {
                    model.highspeedplc = Convert.ToString(row["highspeedplc"].ToString());
                }
                if (row["djhighspeedplc"] != DBNull.Value)
                {
                    model.djhighspeedplc = Convert.ToString(row["djhighspeedplc"].ToString());
                }
                if (row["mediumspeedplc"] != DBNull.Value)
                {
                    model.mediumspeedplc = Convert.ToString(row["mediumspeedplc"].ToString());
                }
                if (row["lowspeedplc"] != DBNull.Value)
                {
                    model.lowspeedplc = Convert.ToString(row["lowspeedplc"].ToString());
                }
                if (row["djlowspeedplc"] != DBNull.Value)
                {
                    model.djlowspeedplc = Convert.ToString(row["djlowspeedplc"].ToString());
                }
                if (row["djmediumspeedplc"] != DBNull.Value)
                {
                    model.djmediumspeedplc = Convert.ToString(row["djmediumspeedplc"].ToString());
                }
                if (row["beforecloseplc"] != DBNull.Value)
                {
                    model.beforecloseplc = Convert.ToString(row["beforecloseplc"].ToString());
                }
                if (row["contacttimeplc"] != DBNull.Value)
                {
                    model.contacttimeplc = Convert.ToString(row["contacttimeplc"].ToString());
                }
                if (row["statusplc"] != DBNull.Value)
                {
                    model.statusplc = Convert.ToString(row["statusplc"].ToString());
                }
                if (row["finishcountplc"] != DBNull.Value)
                {
                    model.finishcountplc = Convert.ToString(row["finishcountplc"].ToString());
                }
                if (row["realqtyplc"] != DBNull.Value)
                {
                    model.realqtyplc = Convert.ToString(row["realqtyplc"].ToString());
                }
                if (row["planqtyplc"] != DBNull.Value)
                {
                    model.planqtyplc = Convert.ToString(row["planqtyplc"].ToString());
                }
                if (row["errorqtyplc"] != DBNull.Value)
                {
                    model.errorqtyplc = Convert.ToString(row["errorqtyplc"].ToString());
                }
                if (row["saveflagplc"] != DBNull.Value)
                {
                    model.saveflagplc = Convert.ToString(row["saveflagplc"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="strWhere">限制条件</param>
        /// <returns>DataSet</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select H.warehouseid,H.warehouseno,H.warehousename,H.materialid,H.highspeed,H.mediumspeed,H.lowspeed,H.beforeclose,H.contacttime,H.active,H.createtime,H.creatby,
                            H.updatetime,H.updateby,M.materialname from materialwarehouse H left join material M on H.materialid=M.materialid");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by H.warehouseno ");
            return SqlHelper.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="strWhere">限制条件</param>
        /// <param name="sqlPara">参数</param>
        /// <returns>DataSet</returns>
        public DataSet GetList(string strWhere, SqlParameter[] sqlPara)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select warehouseid,warehouseno,materialid,highspeed,mediumspeed,lowspeed,beforeclose,contacttime,active,createtime,creatby,
                            updatetime,updateby from materialwarehouse");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by ");
            return SqlHelper.ExecuteDataSet(CommandType.Text, strSql.ToString(), sqlPara);
        }

        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************

        #endregion 成员方法
    }
}